<!--!
This file is a part of MediaDrop (https://www.mediadrop.video),
Copyright 2009-2018 MediaDrop contributors
For the exact contribution history, see the git revision log.
The source code contained in this file is licensed under the GPLv3 or
(at your option) any later version.
See LICENSE.txt in the main project directory, for more information.
-->
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:i18n="http://genshi.edgewall.org/i18n"
      xmlns:xi="http://www.w3.org/2001/XInclude"
      py:strip="">

	<py:def function="media_grid(media, id=None, thumb_size='s', title_len=60, desc_len=95)"
	        py:with="thumb_xy = config['thumb_sizes']['media'][thumb_size]; 
	                 show_like = settings['appearance_show_like'] and settings.get('likes') != 'facebook';">
		<ul id="${id}" class="grid ${thumb_size}-grid">
			<li py:for="m in media"
			    py:with="title = h.strip_xhtml(m.title, True);
			             m_desc_len = desc_len and (desc_len - min(len(m.title), title_len)) or 0">
				<a href="${h.url_for_media(m)}" title="${title}">
					<strong class="grid-title">${h.truncate(title, title_len)}</strong>
					<span class="thumb-wrap">
						<img src="${h.thumb_url(m, thumb_size)}" width="${thumb_xy[0]}" height="${thumb_xy[1]}" alt="" />
						<py:if test="m.duration">
							<span class="thumb-duration" py:content="h.duration_from_seconds(m.duration)">Duration</span>
							<span class="thumb-duration-right" />
						</py:if>
					</span><br />
					<span py:if="m_desc_len > 0" class="grid-desc mcore-text" py:content="h.truncate(m.description_plain, m_desc_len)">Description</span><br py:if="m_desc_len > 0" />
					<span class="grid-meta mcore-text">
						<span py:if="show_like" class="meta meta-likes" title="${m.likes} ${ungettext('Like', 'Likes', m.likes)}">${h.format_decimal(m.likes)} <span>${ungettext('Like', 'Likes', m.likes)}</span></span>
						<span class="meta meta-views" title="${m.views} ${ungettext('View', 'Views', m.views)}">${h.format_decimal(m.views)} <span>${ungettext('View', 'Views', m.views)}</span></span>
					</span>
				</a>
			</li>
		</ul>
	</py:def>

	<!--! Display pagination controls.
	      XXX: This depends on ugly global template vars to generate correct
	           links for filtered media pages. See the inner py:def pagelink. -->
	<py:def function="pager(paginator, radius=2, show_if_single_page=False)" py:with="
		leftmost_page = max(paginator.first_page, paginator.page - radius);
		rightmost_page = min(paginator.last_page, paginator.page + radius);
	">
		<!--! This duplicates the behaviour of paginator.pager() since it has yet to be updated for Pylons .10.
		      We should be able to revert to it later, as it will likely perform better. -->
		<div class="mcore-pager clearfix" py:if="paginator.page_count > (not show_if_single_page and 1 or 0)">
			<a py:def="pagelink(page, text=None, strong=False)"
			   href="${h.url_for(page=page, show=value_of('show'), q=value_of('search_query'), tag=defined('tag') and hasattr(tag, 'slug') and tag.slug or None)}"
			   class="mcore-btn mcore-btn-grey mcore-pager-link"><span><strong py:strip="not strong">${text or page}</strong></span></a>
			<span class="mcore-pager-label">Page:</span>
			<a py:if="paginator.page &gt; paginator.first_page" py:replace="pagelink(paginator.page - 1, Markup('&laquo;'), True)" />
			<py:if test="leftmost_page > paginator.first_page">
				<a py:replace="pagelink(paginator.first_page)" />
				<span py:if="leftmost_page - paginator.first_page > 1" class="mcore-pager-dotdot">..</span>
			</py:if>
			<py:for each="page in xrange(leftmost_page, rightmost_page + 1)" py:choose="">
				<span py:when="paginator.page == page" class="mcore-btn mcore-btn-grey active mcore-pager-current"><span><strong>${page}</strong></span></span>
				<a py:otherwise="" py:replace="pagelink(page)" />
			</py:for>
			<py:if test="paginator.last_page > rightmost_page">
				<span py:if="paginator.last_page - rightmost_page > 1" class="mcore-pager-dotdot">..</span>
				<a py:replace="pagelink(paginator.last_page)" />
			</py:if>
			<a py:if="paginator.page &lt; paginator.last_page" py:replace="pagelink(paginator.page + 1, Markup('&raquo;'), True)" />
		</div>
	</py:def>

	<py:def function="library_controls(show='latest', paginator=None, search_query=None, **kwargs)">
		<div id="library-controls" class="clearfix">
			<span id="library-show">Show:</span>
			<ul>
				<li><a py:strip="show == 'latest'" href="${h.url_for(show='latest', q=search_query, **kwargs)}" class="underline-hover">Latest</a></li>
				<li><a py:strip="show == 'popular'" href="${h.url_for(show='popular', q=search_query, **kwargs)}" class="underline-hover">Most Popular</a></li>
				<li><a py:strip="show == 'featured'" href="${h.url_for(show='featured', q=search_query, **kwargs)}" class="underline-hover">Featured</a></li>
			</ul>
			<div class="f-rgt">Page ${paginator.page} of ${paginator.page_count}</div>
		</div>
	</py:def>

	<py:def function="xhtml_description(fieldName)">
		<div class="xhtml-description-helper">
			<p i18n:msg="fieldName, formattingList">The ${fieldName} field accepts some HTML formatting: ${h.list_acceptable_xhtml()['tags']}</p>
			<!--!
			<ul class="xhtml_description">
				<li><em>Tags:</em> ${h.list_acceptable_xhtml()['tags']}.</li>
				<li><em>Attributes:</em> ${h.list_acceptable_xhtml()['attrs']}</li>
				<li><em>Some tag conversions</em> will be made automatically: ${h.list_acceptable_xhtml()['map']}</li>
			</ul>
			-->
		</div>
	</py:def>

</html>
